var searchv = new Vue({
	el: "#app",
	data: {
		s5,
		curId: '',
		store: '',
		cate: '',
		related_cate: '',
		shopList: ''
	},
	computed: {

	},
	watch: {

	},
	created: function() {
		if (document.URL.indexOf("?") < 0) return; //获取当前url地址,如果没参数.直接返回
		var str = document.URL.split("?")[1];
		var obj = {};
		var arr;
		//当只有一个参数传过来时
		if (str.indexOf("&") < 0) {
			if (str.indexOf("=") < 0) return;
			arr = str.split("=");
			obj[arr[0]] = arr[1];
			this.curId = obj
			return obj;
		}
	},
	mounted: function() {
		this.getcashcardDetail()
		this.getLocation()
	},
	methods: {
		getcashcardDetail() {
			var that = this
			s5.initData({
				url: '/cashcard-my-detail',
				type: "post",
				data: {
					id: this.curId.id
				}
			}, (res) => {

				var data = JSON.parse(res);
				if (data.code != 200) {
					weui.confirm(data.msg, {
						title: '温馨提示',
						buttons: [{
							label: 'NO',
							type: 'default',
							onClick: function() {
								console.log('no')
							}
						}, {
							label: 'YES',
							type: 'primary',
							onClick: function() {
								window.location.href = 'index.html'
								console.log('yes')
							}
						}]
					});
				}
				that.store = data.data;
				that.cate = that.store.cate;
				that.related_cate = that.store.related_cate
			})
		},
		getLocation() {
			var that = this;
			setTimeout(()=>{
				var lng = localStorage.getItem("lng");
				var lat = localStorage.getItem("lat");
				s5.initData({
					url: "/stores-nearby",
					type: 'post',
					data: {
						lat: lat,
						lng: lng,
						related_cate: that.related_cate
					}
				},(res)=>{
					var data = JSON.parse(res);
					if(data.code !=200){
						weui.confirm(data.msg, {
							title: '温馨提示',
							buttons: [{
								label: 'NO',
								type: 'default',
								onClick: function() {
									console.log('no')
								}
							}, {
								label: 'YES',
								type: 'primary',
								onClick: function() {
									window.location.href = 'index.html'
									console.log('yes')
								}
							}]
						});
					}
					that.shopList = data.data.list
				})
			},500)
		},
		toGoodsDetail(id) {
			window.location.href = "store-detail.html?id=" + id
		}
}
})
